package zhongbo.java.air.dictionary.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AirCraft;
import zhongbo.java.air.dictionary.service.IAirCraftService;

/**
 * 说明：
 * 飞机基础信息操作的相关接口
 *
 * @author 钟波dellNotebook
 * @since 2025年03月31日 星期一 08:30:28
 */
@RestController
@RequestMapping("/airCraft")
@Api(tags = "飞机信息")
public class AirCraftController {


    @Autowired
    IAirCraftService iAirCraftService;


    @PostMapping("/insert")
    @ApiOperation("添加")
    public ResultVo<AirCraft>  insert(@RequestBody AirCraft airCraft){

     AirCraft airCraft1 =iAirCraftService.insert(airCraft);

        return ResultVo.ok(airCraft1);
    }



    @PostMapping("/delete")
    @ApiOperation("根据id删除全部信息")
    public ResultVo<String> delete( String id){
        String ok =iAirCraftService.delete(id);
        return ResultVo.ok(ok);
    }

//更新状态
    @PostMapping("/update")
    @ApiOperation("更新")
    public ResultVo<AirCraft> update( @RequestBody AirCraft airCraft){
      AirCraft ss = iAirCraftService.updateStatus(airCraft);
      if(ss!=null){
          return ResultVo.ok(airCraft);
      }
      return ResultVo.failed();
    }

    //根据id查询
    @PostMapping("/select")
    @ApiOperation("查询")
    public ResultVo<AirCraft> select( String id){
        AirCraft airCraft =iAirCraftService.select(id);
        return ResultVo.ok(airCraft);
    }

    @ResponseBody
    @RequestMapping(value = "/page", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "分页条件查询记录接口")
    public ResultVo<PageVo<AirCraft>> findPage(
            @RequestParam(required = false) String id
            , @RequestParam(required = false, defaultValue = "1") int pageNumber
            , @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        PageVo<AirCraft> page = iAirCraftService.findPage(id, pageNumber, pageSize);
        return ResultVo.ok(page);
    }






}
